cmake_minimum_required(VERSION 3.10)

project(OpenSees_GPUSolver LANGUAGES CXX CUDA)

# 设置C++标准为C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 设置CUDA标准为C++17
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)

# 查找CUDA包
find_package(CUDA REQUIRED)
include_directories(${CUDA_INCLUDE_DIRS})

# 添加源文件
set(SOURCES
    GPUSolver.cpp
)

# 添加CUDA源文件
set(CUDA_SOURCES
    GPUMatrixKernels.cu
    FastVectorOps.cu
    GPUElementKernels.cu
    GPUMatrixAssembly.cu
    GPUSolver_Preconditioner.cu
)

# 创建库
add_library(OpenSees_GPUSolver SHARED ${SOURCES} ${CUDA_SOURCES})

# 设置CUDA架构
set_target_properties(OpenSees_GPUSolver PROPERTIES
    CUDA_SEPARABLE_COMPILATION ON
    CUDA_ARCHITECTURES "50;60;70;75;80"
)

# 链接CUDA库
target_link_libraries(OpenSees_GPUSolver
    ${CUDA_LIBRARIES}
    ${CUDA_cusparse_LIBRARY}
    ${CUDA_cusolver_LIBRARY}
    ${CUDA_cublas_LIBRARY}
)

# 指定包含目录
target_include_directories(OpenSees_GPUSolver PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/..
    # OpenSees包含目录
    ${CMAKE_SOURCE_DIR}/include
    ${CMAKE_SOURCE_DIR}/SRC
) 